local weijiu = fk.CreateSkill{
  name = "xiaobai__weijiu"
}

Fk:loadTranslationTable{
  ["xiaobai__weijiu"] = "委纠",
  [":xiaobai__weijiu"] = "准备阶段，你可以令至多三名不同的角色获得“彰重”至你下回合开始，有“彰重”的角色对另一名有“彰重”的角色造成伤害后获得其一张牌。",

  ["#xiaobai__weijiu"] = "委纠：请选择至多三名不同的角色获得“彰重”至你下回合开始",
  ["#xiaobai__weijiu-choose"] = "委纠：获得 %dest 的一张牌",
}

weijiu:addEffect(fk.EventPhaseStart, {
  anim_type = "control",
  can_trigger = function (self, event, target, player, data)
    return data.phase == Player.Start and target == player and player:hasSkill(weijiu.name)
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local choices = room:askToChoosePlayers(player, {
      max_num = 3,
      min_num = 1,
      skill_name = weijiu.name,
      targets = room.alive_players,
      cancelable = true,
      prompt = "#xiaobai__weijiu"
    })
    if #choices == 0 then return end
    event:setCostData(self, {targets = choices})
    return true
  end,
  on_use = function (self, event, target, player, data)
    local choices = event:getCostData(self).targets
    local room = player.room
    room:sortByAction(choices)
    for _, p in ipairs(choices) do
      room:handleAddLoseSkills(p, "xiaobai__zhangchong")
    end
    room:setPlayerMark(player, weijiu.name, choices)
  end
})

weijiu:addEffect(fk.TurnStart, {
  is_delay_effect = true,
  global = true,
  anim_type = "control",
  can_trigger = function (self, event, target, player, data)
    return #player:getTableMark(weijiu.name) > 0 and target == player
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local choices = player:getTableMark(weijiu.name)
    local room = player.room
    for _, p in ipairs(choices) do
      room:handleAddLoseSkills(p, "-xiaobai__zhangchong")
    end
    room:setPlayerMark(player, weijiu.name, 0)
  end
})

weijiu:addEffect(fk.Damage, {
  anim_type = "control",
  can_trigger = function (self, event, target, player, data)
    return target:hasSkill("xiaobai__zhangchong") and player:hasSkill(weijiu.name) and data.to ~= target and not data.to:isNude() and data.to:hasSkill("xiaobai__zhangchong")
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local c = room:askToChooseCard(target, {
      skill_name = weijiu.name,
      target = data.to,
      cancelable = false,
      flag = "he",
      prompt = "#xiaobai__weijiu-choose::"..data.to.id,
    })
    room:obtainCard(target, c, false, fk.ReasonPrey, player, weijiu.name)
  end
})

return weijiu